import 'package:ditieapp/page/city/ciry.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import '../provider/LoginProvider.dart';
import '../yuekangma/ykm.dart';


// 萤石云参数
String appKey = 'd83f034dce1c436db7fe1390826184f7';
String accessToken = 'at.c5xgbsz9c4heiqhobflvgkpy0oaq9hho-5tqfj7mrcv-0v8wz6u-pl1n2glei';
String deviceSerial = 'L36155057';
String verifyCode = 'VSYMIL';
int cameraNo = 1;


class XcmPage extends StatefulWidget {


  @override
  _XcmPageState createState() => _XcmPageState();
}

class _XcmPageState extends State<XcmPage> with TickerProviderStateMixin {
  bool cityStart = false;
  late BuildContext dialogContext;
  var _count = 0;
  /// 动画控制器，动画持续时间5秒，可重复播放
  late final AnimationController _controllerants = AnimationController(
    duration: const Duration(seconds: 1),
    vsync: this,
  )..repeat(reverse: true);

  /// 缩小至 0.2倍大小，放大至3倍大小 非线性动画
  late final Animation<double> _animationstr =
      Tween<double>(begin: 1, end: 1.3).animate(
    CurvedAnimation(
      parent: _controllerants,
      curve: Curves.easeInCirc,
    ),
  );

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

  }

  @override
  void dispose() {
    // TODO: implement dispose
    _controllerants.dispose();
    super.dispose();

  }

  @override
  Widget build(BuildContext context) {
    return AnimatedSwitcher(
      transitionBuilder: (child, anim) {
        var tween = Tween<Offset>(begin: Offset(1, 0), end: Offset(0, 0));
        return SlideTransition(
          position: tween.animate(anim),
          child: child,
        );
      },
      duration: Duration(milliseconds: 500),
      child: InkWell(
        key: ValueKey(_count),
        onTap: () {
          print("点击了加载中");

          /// 延时2s执行返回

          print('延时2s执行');
          // });
          //context.read<LoginProvider>().setCityStart(true);

          // //print(context.read<LoginProvider>().getCityStart().toString());
          // Future.delayed(const Duration(milliseconds: 500), () {
          //
          //
          // });

          // if (cityStart) {
          //   context.read<LoginProvider>().setCityStart(false);
          //   setState(() {
          //     cityStart = false;
          //   });
          // } else {
          //   context.read<LoginProvider>().setCityStart(true);
          //   setState(() {
          //     cityStart = true;
          //   });
          // }

          if(_count == 0){
            showDialog(
                context: context,
                barrierColor: Colors.transparent, //背景透明
                barrierDismissible: true, // 屏蔽点击对话框外部自动关闭
                builder: (BuildContext context) {
                  dialogContext = context;
                  print(context.toString());
                  return YmDialog("加载中…");
                });
          }


          /// 延时2s执行返回
          Future.delayed(Duration(seconds: 2), (){
            Navigator.pop(dialogContext);
          });

          if (_count == 1) {
            setState(() {
              _count = 0;
            });
          } else {
            setState(() {
              _count = 1;
            });
          }

          print(cityStart.toString());
          //:Container(width: 100,height: 100,color: Colors.orange,)
        },
        child:  _count == 0
            ? Container(
                width: 310,
                height: 540,
                child: ListView(
                  children: [
                    Container(
                      width: 310,
                      height: 430,
                      decoration: BoxDecoration(
                        color: Colors.orange,
                          image: DecorationImage(
                              image: AssetImage("lib/assets/ykm/xcm.png"),
                              fit: BoxFit.fill),
                          borderRadius: BorderRadius.only(
                            topLeft: Radius.circular(0),
                            topRight: Radius.circular(0),
                            bottomLeft: Radius.circular(10),
                            bottomRight: Radius.circular(10),
                          )),
                      child: Padding(
                        padding: EdgeInsets.only(top: 104),
                        child: Container(alignment: Alignment.center,width: 310,height: 210,child:context
                            .read<LoginProvider>()
                            .getPhones() == "null"?Text(""): Text(""+"" +
                            context
                                .read<LoginProvider>()
                                .getPhones()
                                .toString()
                                .substring(0, 3) +
                            "****" +
                            context
                                .read<LoginProvider>()
                                .getPhones()
                                .toString()
                                .substring(7, 11),style: TextStyle(fontSize: 21,color: Colors.black,fontWeight: FontWeight.w600),),),
                      ),
                    ),
                  ],
                ),
              )
            : Stack(
                  children: [
                    Container(
                      // color: Color.fromRGBO(83, 165, 108, 1),
                      color: Color.fromRGBO(83, 165, 108, 1),
                      width: MediaQuery.of(context).size.width,
                      height: 540,
                      child: ListView(
                        children: [
                          Container(
                            alignment: Alignment.center,
                            width: 300,
                            height: 70,
                            color: Color.fromRGBO(83, 165, 108, 1),
                            child: Text(
                              "通信大数据行程卡",
                              style: TextStyle(
                                  fontSize: 28,
                                  fontWeight: FontWeight.w700,
                                  color: Colors.white),
                            ),
                          ),
                          Container(
                            alignment: Alignment.center,
                            width: 30,
                            height: 30,
                            color: Color.fromRGBO(83, 165, 108, 1),
                            child: Text(
                              "疫情防控,人人有责",
                              style: TextStyle(
                                  fontSize: 16,
                                  fontWeight: FontWeight.w700,
                                  color: Color.fromRGBO(255, 255, 255, 1)),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 25, right: 25),
                            child: Container(
                              width: MediaQuery.of(context).size.width,
                              height: 368,
                              color: Color.fromRGBO(83, 165, 108, 1),
                              child: Container(
                                width: 200,
                                height: 300,
                                decoration: BoxDecoration(
                                  color: Colors.white,
                                  borderRadius: BorderRadius.circular(20),
                                ),
                                child: Stack(
                                  alignment: AlignmentDirectional.topCenter,
                                  children: [
                                    Container(
                                      width: MediaQuery.of(context).size.width,
                                      height: 30,
                                      decoration: BoxDecoration(
                                        color: Color.fromRGBO(218, 238, 226, 1),
                                        borderRadius: BorderRadius.only(
                                          topLeft: Radius.circular(20),
                                          topRight: Radius.circular(20),
                                          bottomLeft: Radius.circular(0),
                                          bottomRight: Radius.circular(0),
                                        ),
                                      ),
                                    ),
                                    Container(
                                      alignment: Alignment.center,
                                      width: MediaQuery.of(context).size.width,
                                      height: 46,
                                      child: Container(
                                        width: 200,
                                        height: 46,
                                        decoration: BoxDecoration(
                                          color: Color.fromRGBO(218, 238, 226, 1),
                                          borderRadius: BorderRadius.only(
                                            topLeft: Radius.circular(0),
                                            topRight: Radius.circular(0),
                                            bottomLeft: Radius.circular(22),
                                            bottomRight: Radius.circular(22),
                                          ),
                                        ),
                                      ),
                                    ),
                                    Positioned(
                                      top: 10,
                                      left: 95,
                                      child: Container(
                                          alignment: Alignment.center,
                                          width:
                                              MediaQuery.of(context).size.width,
                                          height: 30,
                                          //color: Colors.yellow,
                                          child: Row(
                                            children: [
                                              Text(
                                                "请收下绿色行程卡",
                                                textAlign: TextAlign.center,
                                                style: TextStyle(
                                                    fontSize: 16,
                                                    color: Color.fromRGBO(
                                                        83, 165, 108, 1)),
                                              )
                                            ],
                                          )),
                                    ),
                                    Positioned(
                                      top: 65,
                                      child: Container(
                                        alignment: Alignment.center,
                                        child: context
                                            .read<LoginProvider>()
                                            .getPhones() == "null"?Text(""): Text(
                                          "" +
                                              context
                                                  .read<LoginProvider>()
                                                  .getPhones()
                                                  .toString()
                                                  .substring(0, 3) +
                                              "****" +
                                              context
                                                  .read<LoginProvider>()
                                                  .getPhones()
                                                  .toString()
                                                  .substring(7, 11) +
                                              "的动态行程卡",
                                          style: TextStyle(
                                              fontSize: 16,
                                              fontWeight: FontWeight.w600),
                                        ),
                                      ),
                                    ),
                                    Positioned(
                                      top: 95,
                                      child: Container(
                                        alignment: Alignment.center,
                                        child: Text(
                                          "更新于: " +
                                              DateTime.now()
                                                  .toString()
                                                  .substring(0, 19),
                                          style: TextStyle(
                                              fontSize: 18,
                                              fontWeight: FontWeight.w600,
                                              color: Color.fromRGBO(
                                                  150, 149, 156, 1)),
                                        ),
                                      ),
                                    ),
                                    Positioned(
                                      top: 145,
                                      child: ScaleTransition(
                                        scale: _animationstr,
                                        child: Container(
                                          width: 140,
                                          height: 140,
                                          child: Image.asset(
                                            "lib/assets/ykm/topykm.png",
                                            fit: BoxFit.fill,
                                          ),
                                        ),
                                      ),
                                    ),
                                    Positioned(
                                      top: 310,
                                      child: Container(
                                        width: 235,
                                        height: 2,
                                        color: Color.fromRGBO(223, 223, 223, 1),
                                      ),
                                    ),
                                    Positioned(
                                      top: 320,
                                      child: Container(
                                        width: 240,
                                        height: 46,
                                        // child: Row(
                                        //   children: [
                                        //     Text(
                                        //       "你于前7天内到达或途径: ",
                                        //       style: TextStyle(
                                        //           color: Color.fromRGBO(178, 177, 182, 1)),
                                        //     ),
                                        //     Text(
                                        //       "广东省深圳市",
                                        //       overflow: TextOverflow.clip,
                                        //       style: TextStyle(
                                        //           color: Color.fromRGBO(38, 38, 38, 1)),
                                        //     ),
                                        //   ],
                                        // ),
                                        child: RichText(
                                            text: TextSpan(
                                                text: '你于前7天内到达或途径: ',
                                                style: TextStyle(
                                                    color: Color.fromRGBO(
                                                        178, 177, 182, 1),
                                                    fontSize: 14,
                                                    fontWeight: FontWeight.w600,
                                                    height: 1.3),
                                                children: <TextSpan>[
                                              TextSpan(
                                                  text: '' + context
                                                .read<LoginProvider>()
                                                .getCityName() == "null"?"":
                                                      context
                                                          .read<LoginProvider>()
                                                          .getCityName()
                                                          .toString(),
                                                  style: TextStyle(
                                                      color: Color.fromRGBO(
                                                          38, 38, 38, 1))),
                                            ])),
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                            ),
                          ),
                          Container(
                            width: MediaQuery.of(context).size.width,
                            height: 24,
                            alignment: Alignment.center,
                            child: Text(
                              "结果包含您在前7天到访的国家 (地区) 与停留4小时以上的国内城市",
                              style: TextStyle(fontSize: 10, color: Colors.white),
                            ),
                          ),
                          Container(
                            width: MediaQuery.of(context).size.width,
                            height: 16,
                            alignment: Alignment.center,
                            child: Text(
                              "色卡仅对到访地作提醒,不关联健康状况",
                              style: TextStyle(fontSize: 10, color: Colors.white),
                            ),
                          ),
                          Container(
                              width: MediaQuery.of(context).size.width,
                              height: 40,
                              alignment: Alignment.center,
                              // child: RichText(
                              //     text: TextSpan(
                              //         text: '————————————————',
                              //         style: TextStyle(fontSize: 10, color: Colors.white),
                              //         children: <TextSpan>[
                              //       TextSpan(
                              //         text: ' 本服务联合提供',
                              //         style: TextStyle(fontSize: 10, color: Colors.white),
                              //       ),
                              //           TextSpan(
                              //             text: ' ————————————————',
                              //             style: TextStyle(fontSize: 10, color: Colors.white),
                              //           ),
                              //     ])),
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  Container(
                                    width: 80,
                                    height: 1,
                                    color: Colors.white,
                                  ),
                                  Text(
                                    "   本服务联合提供   ",
                                    style: TextStyle(color: Colors.white),
                                  ),
                                  Container(
                                    width: 80,
                                    height: 1,
                                    color: Colors.white,
                                  ),
                                ],
                              )),
                          Container(
                            width: MediaQuery.of(context).size.width,
                            height: 30,
                            child: Container(
                              width: MediaQuery.of(context).size.width,
                              height: 30,
                              child: Image.asset(
                                "lib/assets/ykm/logo.png",
                                fit: BoxFit.fill,
                              ),
                            ),
                          ),
                          Container(
                            width: MediaQuery.of(context).size.width,
                            height: 90,
                            alignment: Alignment.topCenter,
                            color: Color.fromRGBO(83, 165, 108, 1),
                            child: Text(
                              "客服热线： 10000 / 10086 / 10010 / 10099",
                              style: TextStyle(color: Colors.white, fontSize: 12),
                            ),
                          ),
                        ],
                      ),
                    ),
                    Positioned(
                      bottom: 0,
                      child: BottomPage(),
                    )
                  ],
                ),
      ),
    );
  }
}
